/**
 * Created by Administrator on 2016/4/24.
 */
$(function(){
    var getIp="http://192.168.1.32:3000/";
    //同步数据操作
    $("#synbutton").on("click",function(){
        var paramP=getSynData();
        var paramS=getSynData1();
        var paramT=getSynData2();
        var paramU=getSynData3();
        var sel= $.Params.create();
        var sel1= $.Params.create();
        var sel2= $.Params.create();
        var sel3= $.Params.create();




            sel.addParams("params",paramP);
            sel.ajax("http://test.s4s.com.cn/wx/product.action?addMore",function(data) {
                if (data.success) {
                    alert("同步成功");
                }
            })



        sel1.addParams("params",paramS);
        sel1.ajax("http://test.s4s.com.cn/wx/empproject.action?addMore",function(data){
            if(data.success){
                alert("同步成功");
            }
        })


        sel2.addParams("params",paramT);
        sel2.ajax("http://test.s4s.com.cn/wx/empprojectstage.action?addMore",function(data){
            if(data.success){
                alert("同步成功");
            }
            })

        sel3.addParams("params",paramU);
        sel3.ajax("http://test.s4s.com.cn/wx/productprojectstage.action?addMore",function(data){
            if(data.success){
                alert("同步成功");
            }
        })



    })
    //得到产出物的数据
    function getSynData(){
        var params=[];
        $.ajax({
            url:getIp+"product/list",
            async:false,
            success:function(data){
                if(data.success){
                    var d=new Date();
                    var createTime=d.format('yyyy-MM-dd hh:mm:ss');
                    $.each(data.rows,function(i,val){
                        var paramT="{\"id\":\""+val._id+"\",\"stageId\":\""+val.stageId+"\",\"progressId\":\""+val.progressId+"\",\"progressName\":\""+val.progressName+"\",\"productName\":\""+val.productName+"\",\"remark\":\""+val.remark+"\",\"createTime\":\""+createTime+"\"}";
                        params.push(paramT);
                    })
                    params="["+params+"]";

                }

            }

        })
        return params;

    }


    //得到同步人员项目
    function getSynData1(){
        var params=[];
        $.ajax({
            url:getIp+"empProject/list",
            async:false,
            success:function(data){
                if(data.success){
                    var d=new Date();
                    var createTime=d.format('yyyy-MM-dd hh:mm:ss');
                    $.each(data.rows,function(i,val){
                        var paramT="{\"id\":\""+val._id+"\",\"projectId\":\""+val.projectId+"\",\"projectName\":\""+val.ProjectName+"\",\"userId\":\""+val.userId+"\",\"userName\":\""+val.userName+"\",\"createTime\":\""+createTime+"\"}";
                        params.push(paramT);
                    })
                    params="["+params+"]";
                }

                }

        })
        return params;

    }
//得到同步人员项目阶段
    function getSynData2(){
        var params=[];
        $.ajax({
            url:getIp+"stageEmployee/list",
            async:false,
            success:function(data){
                if(data.success){
                    var d=new Date();
                    var createTime=d.format('yyyy-MM-dd hh:mm:ss');
                    $.each(data.rows,function(i,val){
                        var paramT="{\"id\":\""+val._id+"\",\"projectId\":\""+val.projectId+"\",\"departmentId\":\""+val.departmentId+"\",\"stageId\":\""+val.stageId+"\",\"progressId\":\""+val.progressId+"\",\"projectStageId\":\""+val.projectStageId+"\",\"userId\":\""+val.UserId+"\",\"roleName\":\""+val.roleName+"\",\"createTime\":\""+createTime+"\"}";
                        params.push(paramT);
                    })
                    params="["+params+"]";
                }

            }

        })
        return params;

    }

//获得阶段产物数据
    function getSynData3(){
        var params=[];
        $.ajax({
            url:getIp+"stageProduct/list",
            async:false,
            success:function(data){
                if(data.success){
                    var d=new Date();
                    var createTime=d.format('yyyy-MM-dd hh:mm:ss');
                    $.each(data.rows,function(i,val){
                        var paramT="{\"id\":\""+val._id+"\",\"projectStageId\":\""+val.projectStageId+"\",\"productId\":\""+val.productId+"\",\"createTime\":\""+createTime+"\"}";
                        params.push(paramT);
                    })
                    params="["+params+"]";
                }

            }

        })
        return params;

    }

})